function [ret usfiles] = verifyMatFiles(files)

    if nargin==0        

        % verifica os arquivos .dat
        usfiles = dir('.\Matlab_data\*_US.mat');               %cria matriz com nomes dos arquivos .DAT (Wiremesh 1)
        num_usfiles = length(usfiles);
        for i=1:num_usfiles

           filename = strrep(usfiles(i).name,'_US.mat','');
           usfiles(i).name=filename;
        end

         % verifica os arquivos .dat
        wmfiles = dir('.\Matlab_data\*_WM.mat');               %cria matriz com nomes dos arquivos .DAT (Wiremesh 1)
        num_wmfiles = length(wmfiles);
        ret=1;
        if(num_usfiles>0)&&(num_wmfiles>0)
            if(num_usfiles~=num_wmfiles)

                if(num_usfiles>num_wmfiles)
                    fprintf('Missing WM files: verify');
                    ret=0;
                else
                    fprintf('Missing US files: verify');
                    ret=0;
                end
            end
        else
            fprintf('Missing files: verify!');
        end
    elseif nargin==1
        % 1 verificar se todos os arquivos US existem
        usfiles = dir('.\Matlab_data\*_US.mat');
        num_usfiles = length(usfiles);    
        num_files = length(files);    
        ret=1;
        find=0;
        if(num_usfiles > 0)
            for i=1:num_files
                for j=1:num_usfiles
                    filenameUS=strrep(usfiles(j).name,'_US.mat','');
                    filenameTXT=files(i).name;
                    if(strcmp(filenameTXT,filenameUS))
                        find=find+1;
                    end               
                end

            end
            if(find~=num_files)                
                fprintf('Missing US files: verify!');
                ret=0;
                return
            end
        else
            fprintf('0 US files: verify!');
            ret=0;
            return
        end
        
        % 2 verificar se todos os arquivos WM existem
        wmfiles = dir('.\Matlab_data\*_WM.mat');
        num_wmfiles = length(wmfiles);    
        num_files = length(files);    
        
        find=0;
        if(num_wmfiles > 0)
            for i=1:num_files
                for j=1:num_wmfiles
                    filename=strrep(wmfiles(j).name,'_WM.mat','');
                    if(strcmp(files(i).name,filename))
                        find=find+1;
                    end               
                end

            end
            if(find~=num_files)
                fprintf('Missing WM files: verify!');
                ret=0;
                return
            end
        else
            fprintf('0 US files: verify!');
            ret=0;
            return
        end
        
        
%         % verifica se tem o mesmo numero de arquivos    
%         if(num_usfiles~=num_wmfiles)
% 
%             if(num_usfiles>num_wmfiles)
%                 fprintf('Missing WM files: verify');
%                 ret=0;
%                 return
%             else
%                 fprintf('Missing US files: verify');
%                 ret=0;
%                 return
%             end
%         else
%             % caso sim, verifica se eles tem os mesmos nomes!
%              find=0;
%              for i=1:num_usfiles             
%                     for j=1:num_wmfiles
%                         wmfilename=strrep(wmfiles(j).name,'._WM.mat','');
%                         usfilename=strrep(usfiles(i).name,'._US.mat','');
%                         if(strcmp(usfilename,wmfilename))
%                             find=find+1;
%                         end               
%                     end
% 
%              end
% 
%             if(find==num_files)
%                 ret=1;
%             else
%                 fprintf('US and WM files are diferent: verify');
%                 ret=0;
%                 return
%             end
%             
%         end
        
        
        
    end
   

end